#include "buletooch_control.h"

flag add;
flag reduce;
flag num = {500};

/* name:buletooch_recieve()
 *  function:recieve data from usart.
 *  input:none
 *  output:none
 *  time:2025-03-11
 */
int buletooch_recieve()
{
    uint8_t recieve_data;
    recieve_data = usart_data_receive(BULETOOCH_TYPE);
    return recieve_data;
}

/* name:buletooch_control()
 *  function:recieve data from usart.
 *  input:none
 *  output:none
 *  time:2025-03-12
 */
void buletooch_control()
{
    switch (buletooch_recieve())
    {
    case 'A':
        forward_set(num.speed);
        break;
    case 'B':
        recoil_set(num.speed);
        break;
    case 'C':
        turn_left_set(num.speed);
        break;
    case 'D':
        turn_right_set(num.speed);
        break;
    case 'E':
        num.speed += 10;
        delay_1ms(50);
        break;
    case 'F':
        num.speed -= 10;
        delay_1ms(50);
        break;
    case 'a':
        stop_set();
        break;
    }
}

/* name:set_speed()
 *  function:On the basis of flag bit to get the statue for speed.
 *           1.add.speed flag is to add the speed num.
 *           2.reduce.speed flag is to reduce the speed num.
 *  input:none
 *  output:none
 *  time:2025-03-17
 */
void set_speed()
{
    if(add.speed == 1)
    {
        num.speed += 10;
        add.speed = 2;
    }
    if(reduce.speed == 1)
    {
        num.speed -= 10;
        reduce.speed = 2;
    }
}
